﻿#pragma once
/**
@author 何炜
@date 2011/4/27
@brief .
@details
*/

namespace GLL
{

	template<class value_type>
	class ObjectIterator
	{
	public:
		virtual unsigned int GetSize() = 0;
		virtual bool HasMore() = 0;
		virtual value_type& GetCurrent() = 0;
		virtual value_type& GetNext() = 0;
	};

	template<class Col_type, class val_type>
	class ObjectIteratorCol : public ObjectIterator<val_type>
	{
		virtual void MoveToNext(){++Iter;}
		unsigned int _Size;
		virtual val_type& GetCurrent() = 0;

	protected:
		typename Col_type::iterator Iter;
		typename Col_type::iterator End;

	public:
		ObjectIteratorCol(){_Size = 0;}
		ObjectIteratorCol(Col_type& col){SetCollection(col);}
		void SetCollection(Col_type& col){Iter = col.begin(); End = col.end(); _Size = col.size();}
		virtual unsigned int GetSize(){return _Size;}
		virtual bool HasMore(){return Iter != End;}
		val_type& GetNext(){val_type& ret = GetCurrent(); MoveToNext(); return ret;}
	};

	template<class Col_type>
	class ObjectIterator_StdCollection : public ObjectIteratorCol<Col_type, typename Col_type::value_type>
	{
		virtual typename Col_type::value_type& GetCurrent(){return *Iter;}
	public:
		ObjectIterator_StdCollection(){}
		ObjectIterator_StdCollection(Col_type& set):ObjectIteratorCol(set){}
	};

	template<class Col_type>
	class ObjectIterator_StdMap : public ObjectIteratorCol<Col_type, typename Col_type::mapped_type>
	{
		virtual typename Col_type::mapped_type& GetCurrent(){return Iter->second; }
	public:
		ObjectIterator_StdMap(){}
		ObjectIterator_StdMap(Col_type& set):ObjectIteratorCol(set){}
	};


	//用法：
	//typedef std::vector<int> IntVec;
	//typedef ObjectIterator_StdCollection<IntVec> IntVec_Iterator;

	//IntVec_Iterator GetInts()
	//{
	//	IntVec vec;
	//	...
	//
	//	reutrn IntVec_Iterator(vec);
	//}



};
